﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsumeAndProduceFactory
{
    static class FactoryLog
    {
        #region TotalProduced
        private static int m_totalProduced = 0;
        public static int TotalProduced
        {
            get { return m_totalProduced; }
        }
        public static void incTotalProduced()
        {
            // 上锁
            m_mutexTotalProduced.WaitOne();

            m_totalProduced++;

            // 解锁
            m_mutexTotalProduced.ReleaseMutex();
        }
        #endregion



        #region TotalConsumed

        private static int m_totalConsumed;

        public static int TotalConsumed
        {
            get { return m_totalConsumed; }
        }
        public static void incTotalConsumed()
        {
            // 上锁
            m_mutexTotalConsumed.WaitOne();

            m_totalConsumed++;

            // 解锁
            m_mutexTotalConsumed.ReleaseMutex();
        }
        #endregion



        #region timeWaitProducer
        // 分钟数 防止溢出
        private static int m_timeWaitProducer = 0;
        private static DateTime m_timeStartProducer;
        public static int TimeWaitProducer
        {
            get { return m_timeWaitProducer; }
        }
        public static DateTime TimeStartProducer
        {
            get { return m_timeStartProducer; }
        }
        public static void setProStartTime(DateTime startTime)
        {
            m_timeStartProducer = startTime;
        }
        public static void addProMoreTime(DateTime curTime)
        {
            // 上锁
            m_mutexTimeExec.WaitOne();

            m_timeWaitProducer += curTime.Subtract(m_timeStartProducer).Minutes;

            // 解锁
            m_mutexTimeExec.ReleaseMutex();
        }
        #endregion

        #region timeWaitConsumer
        private static int m_timeWaitConsumer;
        private static DateTime m_timeStartConsumer;
        public static int TimeWaitConsumer
        {
            get { return m_timeWaitConsumer; }
        }
        public static DateTime TimeStartConsumer
        {
            get { return m_timeStartConsumer; }
        }
        public static void setCusStartTime(DateTime startTime)
        {
            m_timeStartConsumer = startTime;
        }
        public static void addCusMoreTime(DateTime curTime)
        {
            // 上锁
            m_mutexTimeExec.WaitOne();

            m_timeWaitConsumer += curTime.Subtract(m_timeStartProducer).Minutes;

            // 解锁
            m_mutexTimeExec.ReleaseMutex();
        }
        #endregion

        private static Mutex m_mutexTotalProduced = new Mutex();
        private static Mutex m_mutexTotalConsumed = new Mutex();
        private static Mutex m_mutexTimeExec = new Mutex();
    }
}
